# uds-system-agent не нужен в LiveCD,
# но systemd preset в пакете автоматически enable его,
# поэтому здесь его выключаем (если установлен), а в post-install/10-mos.sh включаем
rpm -q uds-system-agent && systemctl disable uds-system-agent.service
rpm -q mos-tele && systemctl disable simtel.service

cat > /etc/anaconda-scripts.d/post-install/10-mos.sh << 'EOF'
#!/bin/sh
# Дата установки дистрибутива (для uds-system-agent)
date -Iseconds > /etc/mosinstall
# Традиционный скрипт обновления
echo '#!/bin/sh' > /root/upd.sh
echo 'dnf --refresh -y upgrade' >> /root/upd.sh
chmod u+x /root/upd.sh
rpm -q uds-system-agent && systemctl enable uds-system-agent.service
rpm -q mos-tele && systemctl enable simtel.service
rpm -q touchegg && systemctl enable touchegg.service
systemctl enable sshd.service
rpm -q mos-auth-core && mos-auth-config enable
product=$(dmidecode | grep -i macbook7 | awk '{print $NF}')
if [ "$product" == "MacBook7,1" ]
then
	test -d /etc/sddm.conf.d && py-ini-config set -c /etc/sddm.conf.d/macbook-sddm.conf General GreeterEnvironment QT_XCB_FORCE_SOFTWARE_OPENGL=1
	py-ini-config set /etc/default/grub -n GRUB_GFXMODE console
fi
EOF
chmod 755 /etc/anaconda-scripts.d/post-install/10-mos.sh

cat > /etc/anaconda-scripts.d/livecd-init/10-mos.sh << 'EOF'
#!/bin/sh
# Автозапуск нужен только в уже установленной системе
rm -fv /etc/xdg/mos/autostart/mos-identify.desktop
# rosa-update-system
rm -fv /etc/xdg/autostart/update_applet.desktop
# dnfdragora-updater-autostart
rm -fv /etc/xdg/autostart/dnfdragora-updater.desktop
# высвечивается в шапке меню Пуск
sed -i'' -e 's,ROSA Live User,MOSTech Live User,g' /etc/passwd
rpm -q mos-welcome-pages-all 2> /dev/null && rpm -e mos-welcome-pages-all
rpm -q mos-welcome-pages-school 2> /dev/null && rpm -e mos-welcome-pages-school
EOF
chmod 755 /etc/anaconda-scripts.d/livecd-init/10-mos.sh

cat >> /etc/anaconda-scripts.d/livecd-init/11-plasma5.sh << 'EOF'
#!/bin/bash
if rpm -q sddm >/dev/null 2>&1; then
	session="$(ls /usr/share/xsessions | grep plasma.desktop$ | head -n1)"
	# Autologin sddm
	echo -e "[Autologin]\nSession=${session}\nUser=live" > /etc/sddm.conf.d/99-autologin-live.conf
fi
# Autologin gdm
if [ -f /etc/gdm/custom.conf ]; then
echo "[daemon]
AutomaticLoginEnable=True
AutomaticLogin=live" > /etc/gdm/custom.conf
fi
# Plasma in gdm
rm -f /usr/share/xsessions/openbox*.desktop
EOF
chmod +x /etc/anaconda-scripts.d/livecd-init/11-plasma5.sh

# Adjust OS name and icon
# Icon=mos из пакета mos-icons-core-classic
sed -i -e 's/ROSA Linux/MOSTech/' -e 's,Icon=anaconda-rosa,Icon=mostech,g' /usr/share/applications/anaconda-rosa.desktop

# Adjust DM configs for both LiveCD and installed system
# https://bugzilla.rosalinux.ru/show_bug.cgi?id=13239
if rpm -q sddm >/dev/null 2>&1; then
	session="$(ls /usr/share/xsessions | grep plasma.desktop$ | head -n1)"
	# default to X11 instead of Wayland
	echo "[Last]" > /var/lib/sddm/state.conf
	echo "Session=/usr/share/xsessions/${session}" >> /var/lib/sddm/state.conf
fi

# added in rosa2023.1 by https://abf.io/import/shadow-utils/commit/6e01eea8
if ! grep -q ^HOME_MODE /etc/login.defs; then
cat >> /etc/login.defs << 'EOF'
#
# Default mode of created home directories (/home/username)
#
HOME_MODE 0750
EOF
fi
